package com.skymobi.cassandra.model;

import java.util.List;
import java.util.Map;

import org.apache.cassandra.service.Column;
import org.apache.cassandra.service.ColumnParent;
import org.apache.cassandra.service.ColumnPath;
import org.apache.cassandra.service.ConsistencyLevel;
import org.apache.cassandra.service.InvalidRequestException;
import org.apache.cassandra.service.NotFoundException;
import org.apache.cassandra.service.SlicePredicate;
import org.apache.cassandra.service.SuperColumn;
import org.apache.cassandra.service.TimedOutException;
import org.apache.cassandra.service.UnavailableException;
import org.apache.thrift.TException;

import com.skymobi.cassandra.service.CassandraClient;

public interface Keyspace {

	/**
	 * 获得cassandra client
	 * 
	 * @return
	 */
	public CassandraClient getClient();

	/**
	 * 通过columnPath获得某个column
	 * 
	 * @param key
	 * @param columnPath
	 * @return
	 * @throws InvalidRequestException
	 * @throws NotFoundException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public Column getColumn(String key, ColumnPath columnPath)
			throws InvalidRequestException, NotFoundException,
			UnavailableException, TException, TimedOutException;

	/**
	 * 通过columnPath获得某个SuperColumn
	 * 
	 * @param key
	 * @param columnPath
	 * @return
	 * @throws InvalidRequestException
	 * @throws NotFoundException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public SuperColumn getSuperColumn(String key, ColumnPath columnPath)
			throws InvalidRequestException, NotFoundException,
			UnavailableException, TException, TimedOutException;

	/**
	 * 通过columnPath,reversed,size获得某个SuperColumn
	 * 
	 * @param key
	 * @param columnPath
	 * @param reversed
	 * @param size
	 * @return
	 * @throws InvalidRequestException
	 * @throws NotFoundException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public SuperColumn getSuperColumn(String key, ColumnPath columnPath,
			boolean reversed, int size) throws InvalidRequestException,
			NotFoundException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 通过columnParent获得key对应的一组column
	 * 
	 * @param key
	 * @param columnParent
	 * @param predicate
	 * @return
	 * @throws InvalidRequestException
	 * @throws NotFoundException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public List<Column> getSlice(String key, ColumnParent columnParent,
			SlicePredicate predicate) throws InvalidRequestException,
			NotFoundException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 通过columnParent获得key对应的一组SuperColumn
	 * 
	 * @param key
	 * @param columnParent
	 * @param predicate
	 * @return
	 * @throws InvalidRequestException
	 * @throws NotFoundException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public List<SuperColumn> getSuperSlice(String key,
			ColumnParent columnParent, SlicePredicate predicate)
			throws InvalidRequestException, NotFoundException,
			UnavailableException, TException, TimedOutException;

	/**
	 * 通过columnPath获得一组key的column
	 * 
	 * @param keys
	 * @param columnPath
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public Map<String, Column> multigetColumn(List<String> keys,
			ColumnPath columnPath) throws InvalidRequestException,
			UnavailableException, TException, TimedOutException;

	/**
	 * 通过columnPath获得一组key的SuperColumn
	 * 
	 * @param keys
	 * @param columnPath
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public Map<String, SuperColumn> multigetSuperColumn(List<String> keys,
			ColumnPath columnPath) throws InvalidRequestException,
			UnavailableException, TException, TimedOutException;

	/**
	 * 通过columnParent获得一组key对应的list<code>column</code>
	 * 
	 * @param keys
	 * @param columnParent
	 * @param predicate
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public Map<String, List<Column>> multigetSlice(List<String> keys,
			ColumnParent columnParent, SlicePredicate predicate)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 通过columnParent获得一组key对应的list<code>SuperColumn</code>
	 * 
	 * @param keys
	 * @param columnParent
	 * @param predicate
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public Map<String, List<SuperColumn>> multigetSuperSlice(List<String> keys,
			ColumnParent columnParent, SlicePredicate predicate)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 插入一个column
	 * 
	 * @param key
	 * @param columnPath
	 * @param value
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public void insert(String key, ColumnPath columnPath, byte[] value)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 通过一个key在不同的cf中插入columns或者supercolumns
	 * 
	 * @param key
	 * @param cfmap
	 * @param superColumnMap
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public void batchInsert(String key, Map<String, List<Column>> cfmap,
			Map<String, List<SuperColumn>> superColumnMap)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 通过指定 的key删除columnPath对应的column
	 * 
	 * @param key
	 * @param columnPath
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public void remove(String key, ColumnPath columnPath)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	/**
	 * 获得指定的keyspace信息
	 * 
	 * @return
	 * @throws NotFoundException
	 * @throws TException
	 */
	public Map<String, Map<String, String>> describeKeyspace()
			throws NotFoundException, TException;

	/**
	 * 获得指定columnParent中的column的个数
	 * 
	 * @param key
	 * @param columnParent
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TException
	 * @throws TimedOutException
	 */
	public int getCount(String key, ColumnParent columnParent)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	public List<String> getRangeSlice(ColumnParent columnParent,
			SlicePredicate predicate, String start, String finish, int count)
			throws InvalidRequestException, UnavailableException, TException,
			TimedOutException;

	public ConsistencyLevel getConsistencyLevel();
}
